package com.zxm.springcloud.service.impl;

import com.zxm.springcloud.dao.AccountDao;
import com.zxm.springcloud.service.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;

@Service
@Slf4j
public class AccountServiceImpl implements AccountService {

    @Resource
    private AccountDao accountDao;

    @Override
    public void decrease(Long userId, BigDecimal money) {
        log.info("********->account-service中扣减账户余额开始");

        /**
         * 模拟超时异常，全局事务回滚
         * 暂停几秒钟线程
         */
//        try {
//            TimeUnit.SECONDS.sleep(20);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }

        int a = 10 / 0;

        accountDao.decrease(userId, money);
        log.info("********->account-service中扣减账户余额结束");
    }
}
